#
# Copyright (c) [2022] Huawei Technologies Co.,Ltd.All rights reserved.
#
# OpenArkCompiler is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
#     http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR
# FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
#

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMIR_FEATURE_FULL=1 -DHIR2MPL_FULL_INFO_DUMP=1 -DENABLE_COV_CHECK=1 -fvisibility=hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMIR_FEATURE_FULL=1 -DHIR2MPL_FULL_INFO_DUMP=1 -DENABLE_COV_CHECK=1 -fvisibility=hidden")

string(REPLACE "-Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

set(include_directories
        ${ANDROID_ROOT}/dalvik
        ${ANDROID_ROOT}/system/core/include
        ${ANDROID_ROOT}/system/core/liblog/include
        ${ANDROID_ROOT}/system/core/libutils/include
        ${ANDROID_ROOT}/system/core/libnativehelper/include_jni
        ${ANDROID_ROOT}/system/core/base/include
        ${ANDROID_ROOT}/system/core/libziparchive/include
        ${ANDROID_ROOT}/art/libartpalette/include
        ${ANDROID_ROOT}/art/libartbase
        ${ANDROID_ROOT}/art/libdexfile
        ${ANDROID_ROOT}/include
        ${HIR2MPL_ROOT}/ast_input/clang/include
        ${HIR2MPL_ROOT}/ast_input/common/include
        ${HIR2MPL_ROOT}/common/include
        ${HIR2MPL_ROOT}/optimize/include
        ${HIR2MPL_ROOT}/bytecode_input/class/include  # hir2mplUT.cpp exists
        ${HIR2MPL_ROOT}/test/common
        ${THIRD_PARTY_ROOT}/bounds_checking_function/include
        ${MAPLEALL_ROOT}/maple_ir/include
        ${MAPLEALL_ROOT}/maple_util/include
        ${MAPLEALL_ROOT}/maple_driver/include
        ${MAPLEALL_ROOT}/mempool/include
        ${MAPLE_ROOT}/build/gtestlib/include
        ${HIR2MPL_ROOT}/bytecode_input/common/include
        ${HIR2MPL_ROOT}/bytecode_input/dex/include
        )

set(deps_hir2mplUT
        libHWSecureC
        libdriver_option
        libmplphase
        libcommandline
        libmplir
        libmplutil
        libmempool
        libmpl2mpl
        lib_hir2mpl_ast_input_clang_lib
        lib_hir2mpl_ast_input_clang
        lib_hir2mpl_ast_input_common
        lib_hir2mpl_common
        lib_hir2mpl_optimize
        ${LLVMLIBDIR}/libclang.so
        ${LLVMLIBDIR}/libclang-cpp.so
        ${LLVMLIBDIR}/libclangFrontend.a
        ${LLVMLIBDIR}/libclangDriver.a
        ${LLVMLIBDIR}/libclangSerialization.a
        ${LLVMLIBDIR}/libclangParse.a
        ${LLVMLIBDIR}/libclangSema.a
        ${LLVMLIBDIR}/libclangEdit.a
        ${LLVMLIBDIR}/libclangLex.a
        ${LLVMLIBDIR}/libclangAnalysis.a
        ${LLVMLIBDIR}/libclangAST.a
        ${LLVMLIBDIR}/libclangBasic.a
        ${LLVMLIBDIR}/libLLVMDemangle.a
        ${LLVMLIBDIR}/libLLVMMCParser.a
        ${LLVMLIBDIR}/libLLVMMC.a
        ${LLVMLIBDIR}/libLLVMBitReader.a
        ${LLVMLIBDIR}/libLLVMCore.a
        ${LLVMLIBDIR}/libLLVMBinaryFormat.a
        ${LLVMLIBDIR}/libLLVMProfileData.a
        ${LLVMLIBDIR}/libLLVMOption.a
        ${LLVMLIBDIR}/libLLVMSupport.a
        ${MAPLE_ROOT}/build/gtestlib/lib/libgmock.so
        ${MAPLE_ROOT}/build/gtestlib/lib/libgmock_main.so
        ${MAPLE_ROOT}/build/gtestlib/lib/libgtest.so
        ${MAPLE_ROOT}/build/gtestlib/lib/libgtest_main.so
        z
        pthread
        )

if (NOT ${ONLY_C} STREQUAL "1")
    list(APPEND deps_hir2mplUT
            lib_hir2mpl_bytecode_input_dex
            lib_hir2mpl_bytecode_input_common
            lib_hir2mpl_bytecode_input_class
            libdexfile
            libziparchive
            libbase
            ${THIRD_PARTY_ROOT}/aosp_modified/system/core/liblog/liblog.a
            )
endif()

set($CMAKE_EXE_LINKER_FLAGS "CMAKE_EXE_LINKER_FLAGS -rdynamic -rdynamic -L${LLVMLIBDIR} -Wl,-rpath,${LLVMLIBDIR} -Wl,-rpath,${MAPLE_ROOT}/build/gtestlib/lib")

set(src_hir2mplUT "")
list(APPEND src_hir2mplUT
        ${HIR2MPL_ROOT}/test/ast_input/clang/ast_expr_test.cpp
        ${HIR2MPL_ROOT}/test/ast_input/clang/ast_var_test.cpp
        )

list(APPEND src_hir2mplUT
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_class2fe_helper_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_class_const_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_class_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_function_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_opcode_helper_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_stack2fe_helper_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_stack_helper_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_stmt_bb_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_stmt_loc_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/class/jbc_util_test.cpp
        )

list(APPEND src_hir2mplUT
        ${HIR2MPL_ROOT}/test/common/base64_test.cpp
        ${HIR2MPL_ROOT}/test/common/basic_io_test.cpp
        ${HIR2MPL_ROOT}/test/common/fe_algorithm_test.cpp
        ${HIR2MPL_ROOT}/test/common/fe_file_ops_test.cpp
        ${HIR2MPL_ROOT}/test/common/fe_file_type_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_cfg_test.cpp
        ${HIR2MPL_ROOT}/test/common/fe_struct_elem_info_test.cpp
        ${HIR2MPL_ROOT}/test/common/fe_type_hierarchy_test.cpp
        ${HIR2MPL_ROOT}/test/common/fe_type_manager_test.cpp
        ${HIR2MPL_ROOT}/test/common/fe_utils_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_builder_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_stmt_dfg_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_stmt_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_test_base.cpp
        ${HIR2MPL_ROOT}/test/common/feir_type_helper_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_type_infer_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_type_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_var_test.cpp
        ${HIR2MPL_ROOT}/test/common/feir_lower_test.cpp
        ${HIR2MPL_ROOT}/test/common/hir2mplUT.cpp
        ${HIR2MPL_ROOT}/test/common/hir2mpl_ut_options.cpp
        ${HIR2MPL_ROOT}/test/common/hir2mpl_ut_regx.cpp
        ${HIR2MPL_ROOT}/test/common/hir2mpl_ut_regx_test.cpp
        )

list(APPEND src_hir2mplUT
        ${HIR2MPL_ROOT}/test/bytecode_input/dex/bc_load_on_demand_type_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/dex/bc_parser_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/dex/bc_util_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/dex/dex_class_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/dex/dex_file_util_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/dex/dex_op_test.cpp
        ${HIR2MPL_ROOT}/test/bytecode_input/dex/dex_reader_test.cpp
        )

#hir2mplUT
add_executable(hir2mplUT "${src_hir2mplUT}")
set_target_properties(hir2mplUT PROPERTIES
        COMPILE_FLAGS ""
        INCLUDE_DIRECTORIES "${include_directories}"
        LINK_LIBRARIES "${deps_hir2mplUT}"
        RUNTIME_OUTPUT_DIRECTORY "${MAPLE_BUILD_OUTPUT}/bin"
        )
